added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / VBCustomCodeAnalysisRule / FieldNamingRule.vb
blobb55f61f9a5d7d9fac014e64e1fc531c1f5f2b626
1 '*************************** Module Header ******************************'
2 ' Module Name: FieldNamingRule.vb
3 ' Project: VBCustomCodeAnalysisRule
4 ' Copyright (c) Microsoft Corporation.
5 '
6 ' The class FieldNamingRule inherits the class Microsoft.FxCop.Sdk.BaseIntrospectionRule
7 ' and override the method
8 ' public ProblemCollection Check(Member member).
9 '
10 ' This rule is use to check whether a field name starts with a lowercase character.
12 ' This source is subject to the Microsoft Public License.
13 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
14 ' All other rights reserved.
16 ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
17 ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
18 ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
19 '**************************************************************************'
21 Imports Microsoft.FxCop.Sdk
23 Friend NotInheritable Class FieldNamingRule
24 Inherits BaseIntrospectionRule
25 ''' <summary>
26 ''' Define the rule name, resource file and resource assembly.
27 ''' </summary>
28 Public Sub New()
29 MyBase.New("FieldNamingRule", "VBCustomCodeAnalysisRule.Rules",
30 GetType(FieldNamingRule).Assembly)
32 End Sub
34 ''' <summary>
35 ''' Check the name of the member if it is a field.
36 ''' If the field is not an event or an static menber, its name should
37 ''' start with a lowercase character.
38 ''' </summary>
39 Public Overrides Function Check(ByVal memb As Member) _
40 As ProblemCollection
41 If TypeOf memb Is Field Then
42 Dim fld As Field = TryCast(memb, Field)
44 If Not (TypeOf fld.Type Is DelegateNode) _
45 AndAlso (Not fld.IsStatic) Then
47 If fld.Name.Name(0) < "a"c _
48 OrElse fld.Name.Name(0) > "z"c Then
50 Me.Problems.Add(New Problem(
51 Me.GetNamedResolution("LowercaseField",
52 fld.Name.Name,
53 fld.DeclaringType.FullName)))
54 End If
55 End If
57 End If
59 Return Me.Problems
60 End Function
62 End Class